<?php
/**
 * Dig Core Factory Service
 * 
 * the Dig_Service_Factory service builds objects
 * and manages the object registry
 *
 */
class Dig_Service_Factory
{
    /**
     * Builds an instance of Zend_Db_Table for the specified model
     *
     * Zend_Db_Table now supports this internally, but this factory registers
     * the model instance with the Dig core, providing a singleton of the model.
     *
     * @example $itemModel = Dig_Service_Core::model('items');
     *
     * @param string $tableName
     * @return Zend_Db_Table
     */
    public static function model($tableName)
    {
        $registryKey = 'dig_model_' . $tableName;
        if(Zend_Registry::isRegistered($registryKey)) {
            // return the existing 
            return Zend_Registry::get($registryKey);
        }
        $table = new Zend_Db_Table(array('name' => $tableName));
        Zend_Registry::set($registryKey, $table);
        return $table;
    }
}
?>